package android.pot.com.smartcar.util;


import android.text.TextUtils;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TextCheckUtil {


    public static String CheckString(String str){
        if (str==null||str.length() == 0||str.equals("null")){
            return "";
        }else{
            return str;
        }
    }





    public static String formateDistance(String str){
        if (str == null||str.length() == 0){
            return "";
        }else{
            String disStr = "";
            try {
                float distance = Float.parseFloat(str);
                if (distance < 1000){
                    disStr = distance+"m";
                }else{
                    float flt = distance/1000;
                    BigDecimal bigDecimal = new BigDecimal(flt);
                    BigDecimal num = bigDecimal.setScale(1,BigDecimal.ROUND_HALF_UP);
                    disStr = num.toString()+"km";
                }
            }catch (Exception e){
                disStr = "";
            }


            return disStr;
        }
    }

    public static String formateScore(String str){
        if (str == null||str.length() == 0){
            return "0.0000";
        }else{
            try {
                BigDecimal bigDecimal = new BigDecimal(str);
                BigDecimal num = bigDecimal.setScale(4,BigDecimal.ROUND_DOWN);
                return num.toString();
            }catch (Exception e){
                return "0.0000";

            }

        }
    }

    public static String formate2Money(String str){
        if (str == null||str.length() == 0){
            return "0.00";
        }else{
            try {
                BigDecimal bigDecimal = new BigDecimal(str);
                BigDecimal num = bigDecimal.setScale(2,BigDecimal.ROUND_DOWN);
                return num.toString();
            }catch (Exception e){
                return "0.00";
            }

        }
    }

    public static String formate222Money(String str){
        if (str == null||str.length() == 0){
            return "0.00";
        }else{
            try {
                BigDecimal bigDecimal = new BigDecimal(str);
                BigDecimal num = bigDecimal.setScale(2,BigDecimal.ROUND_UP);
                return num.toString();
            }catch (Exception e){
                return "0.00";
            }

        }
    }

    public static String formate22Money(String str){
        if (str == null||str.length() == 0){
            return "0.00";
        }else{
            try {
                BigDecimal bigDecimal = new BigDecimal(str);
                BigDecimal num = bigDecimal.setScale(0,BigDecimal.ROUND_DOWN);
                return num.toString();
            }catch (Exception e){
                return "0.00";
            }

        }
    }
    public static String formatePoint(String str){
        if (str == null||str.length() == 0 || str.equals("null")){
            return "0";
        }else{
            try {
                BigDecimal bigDecimal = new BigDecimal(str);
                BigDecimal num = bigDecimal.setScale(0,BigDecimal.ROUND_DOWN);
                return num.toString();
            }catch (Exception e){
                return "0";
            }

        }
    }
    /**
     *  积分转现金
     */
    public static String formatePointToCashStr(String str){
        if (str == null||str.length() == 0){
            return "¥ 0.00";
        }else{
            try {
                Double cash = Double.parseDouble(str)/100;
                BigDecimal bigDecimal = new BigDecimal(cash.toString());
                BigDecimal num = bigDecimal.setScale(2,BigDecimal.ROUND_DOWN);
                return "¥ "+num.toString();
            }catch (Exception e){
                return "¥ 0.00";

            }

        }
    }
    /**
     *  积分转现金
     */
    public static String formatePointToCash(String str){
        if (str == null||str.length() == 0){
            return "0.00";
        }else{
            try {
                Double cash = Double.parseDouble(str)/100;
                BigDecimal bigDecimal = new BigDecimal(cash.toString());
                BigDecimal num = bigDecimal.setScale(2,BigDecimal.ROUND_DOWN);
                return num.toString();
            }catch (Exception e){
                return "0.00";

            }

        }
    }
    /**
     *  现金转积分
     */
    public static String formateCashToPoint(String str){

        if (str == null||str.length() == 0){
            return "0.00";
        }else{
            try {
                Double point = Double.parseDouble(str)*100;
                BigDecimal bigDecimal = new BigDecimal(point);
                BigDecimal num = bigDecimal.setScale(2,BigDecimal.ROUND_DOWN);
                return num.toString();
            }catch (Exception e){
                return "0.00";
            }

        }
    }
    /**
     *  现金转积分
     */
    public static String formatePointToCashs(String str){
        if (str == null||str.length() == 0){
            return "0";
        }else{
            try {
                Double cash = Double.parseDouble(str)/100;
                BigDecimal bigDecimal = new BigDecimal(cash.toString());
                BigDecimal num = bigDecimal.setScale(0,BigDecimal.ROUND_DOWN);
                return num.toString();
            }catch (Exception e){
                return "0";

            }

        }
    }

    public static String getTime(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return format.format(date);
    }



    public static String getTime(long timelong) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(timelong*1000);
        return simpleDateFormat.format(date);
    }
    public static String getDayTime(String timeStr){
        if (TextUtils.isEmpty(timeStr)){
            return "";
        }else{
            SimpleDateFormat s1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                Date tempDate = s1.parse(timeStr);
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                return  format.format(tempDate);
            }catch (Exception e){
                return "";
            }

        }
    }

    public static String getHourTime(String timeStr){
        if (TextUtils.isEmpty(timeStr)){
            return "";
        }else{
            SimpleDateFormat s1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                Date tempDate = s1.parse(timeStr);
                SimpleDateFormat format = new SimpleDateFormat("HH:mm");
                return  format.format(tempDate);
            }catch (Exception e){
                return "";
            }

        }
    }

}